﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GestionePolveriLib.Facades;
using GestionePolveriLib.Utilities;
using GestionePolveriLib.BL;
using ControlsLib;

namespace GestionePolveri2
{
    public partial class TurniUC : UserControl
    {
        public event EventHandler<CustomEventArgs<Turno>> TurnoSelected;
 
        private Turno m_turno = null;

        public Turno Turno
        {
            get { return m_turno; }
            set { m_turno = value; }
        }

        public TurniUC()
        {
            InitializeComponent();

            this.cmbTurni.SelectedIndexChanged += new EventHandler(cmbTurni_SelectedIndexChanged);
        }

        void cmbTurni_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                m_turno = (Turno)this.cmbTurni.SelectedItem;

                if (TurnoSelected != null)
                {
                    TurnoSelected(sender, new CustomEventArgs<Turno>(Actions.ItemSelected, m_turno));
                }
            }
            catch (Exception ex)
            {
            }
        }

        public void Initialize()
        {
            try
            {
                TurniFacade tf = new TurniFacade();

                tf.LoadTurniAsync((result) =>
                {
                    this.cmbTurni.LoadData("Descrizione", "ID", result);
                });
            }
            catch (Exception ex)
            {
            }
        }
    }
}
